use std::fs;
use std::path::{PathBuf};

pub struct ConfigManager {
    pub current_path_cfg: PathBuf,
    pub user_data_path: PathBuf,
    pub visible_track_path: PathBuf,
    pub map_config_path: PathBuf,
    pub track_data_path: PathBuf,
}

impl ConfigManager {
    pub fn new() -> Self {
        let home_path = dirs::home_dir().expect("获取用户主目录失败");
        let cache_path = home_path.join(".spidermap");
        let current_path_cfg = cache_path.join("current_path.cfg");
        let user_data_path = cache_path.join("userdata.json");
        let visible_track_path = cache_path.join("visible-tracks.json");
        let map_config_path = cache_path.join("mapconfig.json");
        let track_data_path = cache_path.join("trackdata");

        // 确保配置目录存在
        fs::create_dir_all(&cache_path).unwrap_or_default();
        fs::create_dir_all(&track_data_path).unwrap_or_default();

        Self {
            current_path_cfg,
            user_data_path,
            visible_track_path,
            map_config_path,
            track_data_path,
        }
    }
}
